import React, { Fragment } from 'react';
import { connect } from "react-redux"
import { loadCityDataAsync, loadIndexDataAsync } from "@/components/main/index/actionCreator"
import City from "@/components/main/index/section/city"
import TopArea from "@/components/main/index/section/toparea"
import HotsRecommend from "@/components/main/index/section/hotsrecommend"
import TourRecommend from "@/components/main/index/section/tourrecommend"
import FloorShow from "@/components/main/index/section/floorshow"
import GetRecommend from "@/components/main/index/section/getrecommend"
import RefreshDown from "@/components/layout/pullrefresh/index"




class Index extends React.Component {
    constructor() {
        super();
        this.state = {
            isCity: true,


        }
    }
    render() {
        return  this.props.indexTopData.length!==0? (
            <Fragment>
                <City  />
                <RefreshDown>
                    <TopArea />
                    <HotsRecommend />
                    <TourRecommend />
                    <FloorShow />
                    <GetRecommend />
                    <div style={{ height: "55px", width: "100%" }}></div>
                </RefreshDown>
            </Fragment>
        ):(null)
    }
    componentDidMount() {
        this.props.pageInit.bind(this)()
    }
}
const mapStateToProps = (state) => {
    // console.log(state.getIn(["indexReducer","indexTopData"]).toJS());
    return {
        //    cityList: state.getIn(['indexReducer', 'cityList']),
        currentCity: state.getIn(['indexReducer', 'currentCity']),
        indexTopData:state.getIn(["indexReducer","indexTopData"])

    }
}
const mapDispatchToProps = (dispatch) => ({
    pageInit() {
        this.props.getIndexData(this.props.currentCity)

    },
    handleCity(res) {
        if (res.name) {
            var currentCity = {
                city_id: res.id,
                abbreviation: res.Abbreviation,
                name: res.name
            }
            this.setState({ isCity: !this.state.isCity })
            this.props.getIndexData(currentCity)
        } else {
            dispatch(loadCityDataAsync(dispatch))
            this.setState({ isCity: !this.state.isCity })

        }


    },
    // handleScroll(event) {
    //     // let clientHeight = document.documentElement.clientHeight; //可视区域高度
    //     let scrollTop = document.documentElement.scrollTop;  //滚动条滚动高度
    //     if (scrollTop == 0) {
    //         this.setState({ style: { background: "rgba(225,235,245,0.5)" } })
    //     } else {
    //         this.setState({ style: { background: "rgba(225,235,245,1)" } })
    //     }
    // },
    getIndexData(currentCity) {
        dispatch(loadIndexDataAsync(dispatch, currentCity))
    }


})
export default connect(mapStateToProps, mapDispatchToProps)(Index)